package com.blog.anxinzhu.dubbo.api.controller;

import graphql.GraphQL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author chenlin
 * @create 2020-12-05  10:47
 */
@Controller
@RequestMapping("graphql")
public class GraphQLController {
    @Autowired
    GraphQL graphQL;

    /**
     * 实现graphQL查询
     * @param query
     * @return
     */
    @GetMapping
    @ResponseBody
    public Map<String,Object> query(@RequestParam("query") String query) {
        return graphQL.execute(query).toSpecification();
    }
}
